local extension = Package:new("test4")
extension.extensionName = "aj_test"

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["test4"] = "测试·四",
}

local jiepade = General:new(extension, "test4__jiepade", "test_hu", 4)

Fk:loadTranslationTable{
  ["test4__jiepade"] = "杰帕德",--名字
  ["#test4__jiepade"] = "永屹之壁",--称号
  ["designer:test4__jiepade"] = "zuozhe",--作者
  ["cv:test4__jiepade"] = "cv",--cv
  ["illustrator:test4__jiepade"] = "huashi",--画师

  ['~test4__jiepade'] = '我…还不能…',
}

local shuyu = fk.CreateTriggerSkill{
  name = "test4__shuyu",
  events ={fk.CardUsing,fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    local tos = TargetGroup:getRealTargets(data.tos)
    if player:hasSkill(self.name) and #player:getPile("test4__shuyu") > 0
    and data.card.trueName == "slash" and 
    (table.contains(tos,target.id) or (data.from and data.from == target.id)) then
      local targets = table.filter(player.room:getAlivePlayers(), function(p)
        return player:distanceTo(p) <= #player:getPile("test4__shuyu")
      end)
      return table.contains(targets,target)
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"#test4__shuyu::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(target,"@@test4__shuyu-turn",1)
    room:addTableMarkIfNeed(player,"test4__yongyi",target.id)--永屹记录
    local ids = table.filter(player:getPile("test4__shuyu"),function (id)
      local card = Fk:getCardById(id)
      return card.sub_type == Card.SubtypeWeapon or card.sub_type == Card.SubtypeArmor 
    end)
    for _, e in ipairs(ids) do
      local card = Fk:getCardById(e)---@cast card EquipCard
      local skills = card:getEquipSkills(player) 
      for _, s in ipairs(skills) do
        if not target:hasSkill(s,true) then --目标没有的技能
          room:handleAddLoseSkills(target, s.name, "test4__shuyu",false,true)
          room:addTableMarkIfNeed(target,"test4__shuyu-turn",s.name)
        end
      end
    end
  end,
refresh_events = {fk.AfterCardsMove},
can_refresh = function(self, event, target, player, data)
  if not player:getMark("@@test4__shuyu-turn") == 0 then return false end
  for _, move in ipairs(data) do
    for _, info in ipairs(move.moveInfo) do
      if (move.to == player.id and move.toArea == Card.PlayerEquip)
      or (move.from == player.id and info.fromArea == Card.PlayerEquip) then
        local card = Fk:getCardById(info.cardId)
        return card.sub_type == Card.SubtypeWeapon or card.sub_type == Card.SubtypeArmor
      end
    end
  end
end,
on_refresh = function(self, event, target, player, data)
  local room = player.room
  for _, move in ipairs(data) do
    for _, info in ipairs(move.moveInfo) do
      local card = Fk:getCardById(info.cardId)---@cast card EquipCard
      if card.sub_type == Card.SubtypeWeapon or card.sub_type == Card.SubtypeArmor then
        local skills = card:getEquipSkills(player) 
        for _, s in ipairs(skills) do
          if move.to == player.id then
            if table.contains(player:getTableMark("test4__shuyu-turn"),s.name) then
              room:removeTableMark(player,"test4__shuyu-turn",s.name)
            end
          end
        end
      end
    end
  end --#失去的列表技能再获得，获得的技能需要移除列表
  for _, s in ipairs(player:getTableMark("test4__shuyu-turn")) do
    if not player:hasSkill(s,true) then --目标没有的技能
      room:handleAddLoseSkills(player, s, "test4__shuyu",false,true)
    end
  end
end,
on_lose = function (self, player, is_death)
  if #player:getPile("test4__shuyu") then
    player.room:moveCardTo(player:getPile("test4__shuyu"), Card.DiscardPile, nil, fk.ReasonJustMove, "test4__shuyu","test4__shuyu",true,player.id)
  end
end,
}

local shuyu_trigger = fk.CreateTriggerSkill{
  name = "#test4__shuyu_trigger",
  events ={fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and player == target and data.card.type == Card.TypeEquip--使用装备
  end,
  on_use = function(self, event, target, player, data)
    player:addToPile("test4__shuyu",data.card,true,"test4__shuyu")
    return true
  end,
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
    if not player:hasSkill("test4__shuyu", true, true) then return false end
    local t = false
    for _, move in ipairs(data) do
      if table.find(move.moveInfo,function (info)
        return player:getPileNameOfId(info.cardId) == "test4__shuyu" or 
        (info.fromArea == Card.PlayerSpecial and info.fromSpecialName == "test4__shuyu")
      end) then
        t = true
        break
      end
    end
    return t
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local ids = table.filter(player:getPile("test4__shuyu"),function (id)
      local card = Fk:getCardById(id)
      return card.sub_type == Card.SubtypeWeapon or card.sub_type == Card.SubtypeArmor 
    end)
    local name = {}
    for _, e in ipairs(ids) do
      local card = Fk:getCardById(e)---@cast card EquipCard
      local skills = card:getEquipSkills(player) 
      for _, s in ipairs(skills) do
        table.insert(name,s.name)
      end
    end
    for _, t in ipairs(room:getAlivePlayers()) do
      if t:getMark("@@test4__shuyu-turn") > 0 then
        for _, m in ipairs(t:getTableMark("test4__shuyu-turn")) do
          if not table.contains(name,m) and t:hasSkill(m) then
            room:handleAddLoseSkills(t, "-"..m, "test4__shuyu",false,true)
            room:removeTableMark(t,"test4__shuyu-turn",m)
          end
        end
        for _, n in ipairs(name) do
          if not table.contains(t:getTableMark("test4__shuyu-turn"),n) and not t:hasSkill(n) then
            room:handleAddLoseSkills(t, n, "test4__shuyu",false,true)
            room:addTableMarkIfNeed(t,"test4__shuyu-turn",n)
          end
        end
      end
    end
  end,
}

local shuyu_end = fk.CreateTriggerSkill{
  name = "#test4__shuyu_end",
  refresh_events = {fk.TurnEnd},
  can_refresh = function (self, event, target, player, data)
    local p = table.filter(player.room.players,function (p)
      return p:getMark("@@test4__shuyu-turn") > 0
    end)
    self.cost_data = {p = p}
    return #p > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local p = self.cost_data.p
    for _, t in ipairs(p) do
      for _, m in ipairs(t:getTableMark("test4__shuyu-turn")) do
        if t:hasSkill(m) then
          room:handleAddLoseSkills(t, "-"..m, "test4__shuyu",false,true)
        end
      end
    end
  end,
}

local shuyu_lose = fk.CreateTriggerSkill{
  name = "#test4__shuyu_lose",
  refresh_events = {fk.EventLoseSkill},
  can_refresh = function (self, event, target, player, data)
    return target == player and table.contains(player:getTableMark("test4__shuyu-turn"),data.name)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:handleAddLoseSkills(player, data.name, "test4__shuyu",false,true)
  end,
}

Fk:loadTranslationTable{
  ["test4__shuyu"] = "戍御",
  [":test4__shuyu"] = "当你使用装备牌时，可以改为置于武将牌上。当你距离X以内的一名角色成为【杀】的目标或使用者时，你可令该角色于本回合结束前获得你场上所有武器与防具的效果（X为“戍御”牌数）。",

  ["#test4__shuyu_trigger"] = "戍御",
  ["#test4__shuyu_end"] = "戍御",
  ["#test4__shuyu_lose"] = "戍御",
  ["@@test4__shuyu-turn"] = "戍御",
  ["#test4__shuyu"] = "戍御：你可以令%dest获得“戍御”所有武器与防具的效果直到本回合结束",

  ["$test4__shuyu1"] = "奉陪到底。",
  ["$test4__shuyu2"] = "我以朗道之名。",
}

local yongyi = fk.CreateTriggerSkill{
  name = "test4__yongyi",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill("test4__yongyi") then return false end
    local ids = {}
    local room = player.room
    local event_id = room.logic:getCurrentEvent().id

    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        if move.moveReason == fk.ReasonDiscard and move.from and move.proposer and move.from ~= move.proposer then
          
          if #room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
            for _, m in ipairs(e.data) do --完全一致的筛选
              if m.toArea == Card.DiscardPile then
                if m.moveReason == fk.ReasonDiscard and m.from and m.proposer and m.from ~= m.proposer
                and m.from == move.from then
                  for _, info in ipairs(m.moveInfo) do
                    if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
                    e.id ~= event_id then
                      return true
                    end
                  end
                end
              end
            end
          end, Player.HistoryTurn) > 0 then return end
          
          
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
            room:getCardArea(info.cardId) == Card.DiscardPile then
              table.insertIfNeed(ids, info.cardId)
            end
          end
        end
      end
    end
    ids = U.moveCardsHoldingAreaCheck(room, ids)
    if #ids > 0 then
      self.cost_data = {ids = ids}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:obtainCard(player,self.cost_data.ids,true,fk.ReasonJustMove,player.id,"test4__yongyi")
  end,
  refresh_events = {fk.Death},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self, false, true) 
    and #player:getTableMark("test4__yongyi") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(player:getTableMark("test4__yongyi")) do
      room:setPlayerMark(room:getPlayerById(p),"@@test4__yongyi",1)
    end
  end,
}

local function distanceTo(from, other, mode)
  mode = mode or "both"
  if other == from then return 0 end
  if from:isRemoved() or other:isRemoved() then
    return -1
  end
  local right = 0
  local temp = from
  local try_time = 10
  for _ = 0, try_time do
    if temp == other then break end
    if ((not temp.dead and not temp:isRemoved()) 
    or (temp:hasSkill("test4__yongyi",false,true) and temp.dead)) then
      right = right + 1
    end
    temp = temp.next
  end
  if temp ~= other then
    print("Distance malfunction: start and end does not match.")
  end
  local n = #table.filter(Fk:currentRoom().players,function (p)
    return p:hasSkill("test4__yongyi",false,true) and p.dead
  end)
  local left = n + #Fk:currentRoom().alive_players - right - #table.filter(Fk:currentRoom().alive_players, function(p)
    return p:isRemoved()
  end)
  local ret = 0
  if mode == "left" then
    ret = left
  elseif mode == "right" then
    ret = right
  else
    ret = math.min(left, right)
  end

  local status_skills = Fk:currentRoom().status_skills[DistanceSkill] or Util.DummyTable
  for _, skill in ipairs(status_skills) do
    if skill.name ~= "#test4__yongyi_distance" then
      local fixed = skill:getFixed(from, other)
      local correct = skill:getCorrect(from, other)
      if fixed ~= nil then
        ret = fixed
        break
      end
      ret = ret + (correct or 0)
    end
  end

  if from.fixedDistance[other] then
    ret = from.fixedDistance[other]
  end

  return math.max(ret, 1)
end

local yongyi_distance = fk.CreateDistanceSkill{
  name = "#test4__yongyi_distance",
  fixed_func = function(self, from, to)
    return distanceTo(from, to)
  end,
}

local yongyi_attackrange = fk.CreateAttackRangeSkill{
  name = "#test4__yongyi_attackrange",
  correct_func = function (self, from, to)
    if from:getMark("@@test4__yongyi") > 0 then
      return 1
    end
  end,
}

Fk:loadTranslationTable{
  ["test4__yongyi"] = "永屹",
  [":test4__yongyi"] = "锁定技，当每回合你的牌首次被其他角色弃置后，你获得之。当你死亡后，成为过你技能目标的角色攻击范围+1，且本局游戏你仍参与距离计算。",

  ["#test4__yongyi_trigger"] = "永屹",
  ["#test4__yongyi_distance"] = "永屹",
  ["#test4__yongyi_attackrange"] = "永屹",
  ["@@test4__yongyi"] = "永屹",

  ["$test4__yongyi1"] = "有我在。",
  ["$test4__yongyi2"] = "正义已至！",
}

shuyu:addRelatedSkill(shuyu_lose)
shuyu:addRelatedSkill(shuyu_end)
shuyu:addRelatedSkill(shuyu_trigger)
jiepade:addSkill(shuyu)

yongyi:addRelatedSkill(yongyi_attackrange)
yongyi:addRelatedSkill(yongyi_distance)
jiepade:addSkill(yongyi)

local huahuo = General:new(extension, "test4__huahuo", "test_xie", 3, 3, General.Female)

Fk:loadTranslationTable{
  ["test4__huahuo"] = "花火",--名字
  ["#test4__huahuo"] = "焰锦游鱼",--称号
  ["designer:test4__huahuo"] = "zuozhe",--作者
  ["cv:test4__huahuo"] = "cv",--cv
  ["illustrator:test4__huahuo"] = "huashi",--画师

  ['~test4__huahuo'] = '玩大了…',
}

local youyu = fk.CreateTriggerSkill{
  name = "test4__youyu",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player
    and table.contains({Player.Start,Player.Judge, Player.Draw, Player.Play, Player.Discard, Player.Finish}, player.phase) then
      local m = player:getTableMark("test4__youyu-turn")
      player.room:addTableMark(player,"test4__youyu-turn",player:getHandcardNum())
      return not table.contains(m,player:getHandcardNum()) --and #m > 0
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(table.filter(room:getOtherPlayers(player),function (p)
      return not p:isNude()
    end), Util.IdMapper), 1, 1, "#test4__youyu", self.name)
    self.cost_data = {tos = tos}
    return #tos > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local t = room:getPlayerById(self.cost_data.tos[1])
    local c = room:askForCardChosen(player,t,"he",self.name)
    local ids = player:getCardIds("h")
    t:showCards(c)
    room:obtainCard(player,c,true,fk.ReasonPrey,player.id,self.name)
    if #ids > 0 then
      room:obtainCard(t,ids,true,fk.ReasonGive,player.id,self.name)
    else
      player:drawCards(1,self.name)
    end
  end,
}


Fk:loadTranslationTable{
  ["test4__youyu"] = "游鱼",
  [":test4__youyu"] = "你回合内的每个阶段开始时，若你的手牌数与此前阶段开始时均不同，你可以展示并获得一名其他角色的一张牌，然后交给该角色所有其他手牌；若你未交出牌，你摸一张牌。",

  ["#test4__youyu"] = "游鱼：你可以展示一名其他角色的一张牌，将所有手牌与之交换",

  ["test4__youyu-turn"] = "游鱼",

  ["$test4__youyu1"] = "来捉迷藏呀~",
  ["$test4__youyu2"] = "愚蠢的智者，聪明的愚者~",
  ["$test4__youyu3"] = "好戏开场~",
  ["$test4__youyu4"] = "玩得开心吗？嗯~玩得开心就好~",
}


local qianyi = fk.CreateTriggerSkill{
  name = "test4__qianyi",
  frequency = Skill.Compulsory,
  events = {fk.AfterPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player
    and table.contains({Player.Start,Player.Judge, Player.Draw, Player.Play, Player.Discard, Player.Finish}, player.phase) then
      local n = #player.room.logic:getEventsOfScope(GameEvent.Phase, 999, function (e)
        return e.data[1] == player and 
        table.contains({Player.Start,Player.Judge, Player.Draw, Player.Play, Player.Discard, Player.Finish}, e.data[2])
      end, Player.HistoryTurn)
      if n == player:getMark("@test4__qianyi-turn") then
        local m = player:getTableMark("test4__youyu-turn")
        self.cost_data = {n = m[n]}
        return m[n] ~= player:getHandcardNum()
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = self.cost_data.n
    if n > player:getHandcardNum() then
      player:drawCards(n - player:getHandcardNum(),self.name)
    else
      room:askForDiscard(player,player:getHandcardNum() - n,player:getHandcardNum() - n,false,self.name,false)
    end
  end,
  refresh_events = {fk.TurnStart},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self) and target == player
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@test4__qianyi-turn", player:getHandcardNum())
  end,
}

Fk:loadTranslationTable{
["test4__qianyi"] = "千役",
[":test4__qianyi"] = "锁定技，你的第X个阶段结束后，若你手牌数较此阶段发动“游鱼”前变化过，你将手牌数调整至该阶段开始时（X为你回合开始时的手牌数）。",

["@test4__qianyi-turn"] = "千役",

["$test4__qianyi1"] = "愚者千面，游戏人间。",
["$test4__qianyi2"] = "你~会找到答案吗~",
}

huahuo:addSkill(youyu)
huahuo:addSkill(qianyi)

local misha = General:new(extension, "test4__misha", "test_hui", 3)

Fk:loadTranslationTable{
  ["test4__misha"] = "米沙",--名字
  ["#test4__misha"] = "酒店门童",--称号
  ["designer:test4__misha"] = "zuozhe",--作者
  ["cv:test4__misha"] = "cv",--cv
  ["illustrator:test4__misha"] = "huashi",--画师

  ['~test4__misha'] = '招待…不周…',
}

local yingbin = fk.CreateTriggerSkill{
  name = "test4__yingbin",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.to == Player.Start and not target.dead
  end,
  on_use = function(self, event, target, player, data)
    if target:isNude() or #player.room:askForDiscard(target,1,1,true,self.name,true,nil,"#test4__yingbin") == 0 then
      target:drawCards(1,self.name)
      target:skip(Player.Play)
    end
  end,
  refresh_events = {fk.EventPhaseChanging},
  can_refresh = function (self, event, target, player, data)
      return target == player and data.to == Player.Finish
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    data.to = Player.Play
    room:setPlayerMark(player, "@@test4__yingbin-phase", 1)
    if player:hasSkill(self) then
      for _, v in ipairs(room:getOtherPlayers(player)) do
        room:setPlayerMark(v, "test4__yingbin-phase", 1)
      end
    end
  end,
}

local yingbin_prohibit = fk.CreateProhibitSkill{
  name = "#test4__yingbin_prohibit",
  frequency = Skill.Compulsory,
  prohibit_use = function(self, player, card)
    return player:getMark("test4__yingbin-phase") > 0
  end,
  prohibit_response = function (self, player, card)
    return player:getMark("test4__yingbin-phase") > 0
  end
}


Fk:loadTranslationTable{
  ["test4__yingbin"] = "迎宾",
  [":test4__yingbin"] = "锁定技，每个角色的准备阶段，其选择一项：1.摸一张牌并跳过出牌阶段；2.弃一张牌。然后其本回合的结束阶段改为出牌阶段，若其为你，此阶段其他角色不可使用或打出手牌。",

  ["#test4__yingbin"] = "迎宾：你可以弃置一张牌，或取消后摸一张牌并跳过出牌阶段",

  ["@@test4__yingbin-phase"] = "迎宾",

  ["$test4__yingbin1"] = "这次一定让您满意！",
  ["$test4__yingbin2"] = "这位客人，请别生气… ",
  ["$test4__yingbin3"] = "给您添麻烦了…",
}


local wuzhuang = fk.CreateTriggerSkill{
  name = "test4__wuzhuang",
  events ={fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player == target and player:usedSkillTimes(self.name) == 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local n = {}
    if player:getHandcardNum() >= player.maxHp and #room:askForDiscard(target,1,1,true,self.name,true,nil,"#test4__wuzhuang_dis:::"..data.card:toLogString()) > 0 then
      table.insert(n,1)
    end
    if player:getHandcardNum() <= player.hp and room:askForSkillInvoke(player,self.name,nil,"#test4__wuzhuang_draw") then
      table.insert(n,2)
    end
    self.cost_data = {n = n}
    return #n > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = self.cost_data.n
    if table.contains(n,1) then
      data.additionalDamage = (data.additionalDamage or 0) + 1
    end
    if table.contains(n,2) then
      player:drawCards(1,self.name)
    end
    if #n == 2 then
      room:setPlayerMark(player,"test4__wuzhuang-turn",1)
    end
  end,
  on_acquire = function (self, player, is_start)
    player.room.logic:getEventsOfScope(GameEvent.MoveCards, 10086, function(e)
      for _, m in ipairs(e.data) do
        if m.toArea == Card.DiscardPile and m.moveReason == fk.ReasonDiscard and m.from and m.proposer 
        and m.from == m.proposer and m.from == player.id then
          player.room:addPlayerMark(player,"@test4__wuzhuang-turn",#table.filter(m.moveInfo,function (info)
            return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip
          end))
        end
      end
    end, Player.HistoryTurn)
  end,
  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player,"@test4__wuzhuang-turn",0)
  end,
}

local wuzhuang_trigger = fk.CreateTriggerSkill{
  name = "#test4__wuzhuang_trigger",
  events ={fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:getMark("test4__wuzhuang-turn") > 0 and player:getMark("@test4__wuzhuang-turn") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = player:getMark("@test4__wuzhuang-turn") % #room:getAlivePlayers()
    local t = room:getCurrent()
    if n > 0 then
      for _ = 1, n do
        t = t.next
      end
    end
    room:damage{
      from = player,
      to = room:getPlayerById(t.id),
      damage = 1,
      skillName = "test4__wuzhuang",
    }
  end,
  refresh_events ={fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if not player:hasSkill("test4__wuzhuang") then return false end
    for _, m in ipairs(data) do
      if m.toArea == Card.DiscardPile and m.moveReason == fk.ReasonDiscard and m.from and m.proposer 
      and m.from == m.proposer and m.from == player.id then
        for _, info in ipairs(m.moveInfo) do
          return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player,"@test4__wuzhuang-turn",1)
  end,
}


Fk:loadTranslationTable{
["test4__wuzhuang"] = "误撞",
[":test4__wuzhuang"] = "每回合限一次，当你使用牌时，若你的手牌：1.不少于体力上限，你可弃一张牌并令之伤害+1：2.不多于体力值，你可摸一张牌；若两项均触发，本回合结束时你对当前回合角色逆时针第X名角色造成1点伤害（X为你本回合弃置的牌数）。",

["#test4__wuzhuang_trigger"] = "误撞",
["@test4__wuzhuang-turn"] = "误撞",
["#test4__wuzhuang_dis"] = "误撞：你可以弃置一张牌并令%arg伤害+1",
["#test4__wuzhuang_draw"] = "误撞：你可以摸一张牌",

["$test4__wuzhuang1"] = "开始今天的工作吧。",
["$test4__wuzhuang2"] = "请、请让一下！",
}

yingbin:addRelatedSkill(yingbin_prohibit)
misha:addSkill(yingbin)
wuzhuang:addRelatedSkill(wuzhuang_trigger)
misha:addSkill(wuzhuang)


local huangquan = General:new(extension, "test4__huangquan", "test_xu", 4,4,General.Female)

Fk:loadTranslationTable{
  ["test4__huangquan"] = "黄泉",--名字
  ["#test4__huangquan"] = "远辞畴昔",--称号
  ["designer:test4__huangquan"] = "zuozhe",--作者
  ["cv:test4__huangquan"] = "cv",--cv
  ["illustrator:test4__huangquan"] = "huashi",--画师

  ['~test4__huangquan'] = '尘埃，终归大地…',
}

local muyu = fk.CreateTriggerSkill{
  name = "test4__muyu",
  mute = true,
  events = { fk.AfterCardUseDeclared },
  can_trigger = function(self, _, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_cost = function (self, event, target, player, data)
    local all = {"thunder__slash","ice__slash","Cancel"}
    local ask = table.clone(all)
    for _, s in ipairs({"thunder__slash","ice__slash"}) do
      if data.card.name == s then
        table.removeOne(ask,s)
      end
    end
    local choice = player.room:askForChoice(player,ask,self.name,"#test4__muyu",false,all)
    self.cost_data = {name = choice}
    return choice ~= "Cancel"
  end,
  on_use = function (self, event, target, player, data)
    player:broadcastSkillInvoke(self.name,math.random(1,2))
    player.room:notifySkillInvoked(player, self.name)
    local name = self.cost_data.name
    local card = Fk:cloneCard(name, data.card.suit, data.card.number)
    for k, v in pairs(data.card) do
      if card[k] == nil then
        card[k] = v
      end
    end
    if data.card:isVirtual() then
      card.subcards = data.card.subcards
    else
      card.id = data.card.id
    end
    card.skillNames = data.card.skillNames
    card.skillName = "test4__muyu"
    data.card = card
  end,
}

local muyu_trigger = fk.CreateTriggerSkill{
  name = "#test4__muyu_trigger",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player.phase == Player.Finish and #player:getTableMark("test4__muyu-turn") > 0 then
      local n = 0
      for _, id in ipairs(player:getTableMark("test4__muyu-turn")) do
        if Fk:getCardById(id).suit == Card.Spade then
          n = n + Fk:getCardById(id).number
          if n > 8 then return true end
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local ps = room:askForChoosePlayers(player,table.map(room:getAlivePlayers(),Util.IdMapper),1,1,"#test4__muyu-ask","test4__muyu")
    if #ps == 1 then
      self.cost_data = {p = ps[1]}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local p = room:getPlayerById(self.cost_data.p)
    player:broadcastSkillInvoke("test4__muyu",math.random(1,2))
    room:notifySkillInvoked(player, "test4__muyu",nil,{p.id})
    local pattern = ".|2~9|spade"
    local judge = {
      who = p,
      reason = "test4__muyu",
      pattern = pattern,
    }
    room:judge(judge)
    local cards = table.filter(player:getTableMark("test4__muyu-turn"),function (id)
      return Fk:getCardById(id).suit == Card.Spade and id ~= judge.card.id
    end)
    --[[
    if room:askForSkillInvoke(player,"#test4__muyu_trigger",nil,"#test4__muyu_judge") then
      local cid = room:askForCardChosen(player, player, { card_data = { { "test4__muyu", cards } } }, "test4__muyu", "#test4__muyu_judge")
      player:broadcastSkillInvoke("test4__muyu",math.random(3,4))
      player.room:notifySkillInvoked(player, "test4__muyu")
      judge.card = Fk:getCardById(cid, true)
    end
    --]]
    if judge.card:matchPattern(pattern) then
      room:damage{
        to = p,
        damage = 3,
        damageType = fk.ThunderDamage,
        skillName = "lightning",
      }
    end
  end,
refresh_events = {fk.AfterCardsMove},
can_refresh = function(self, event, target, player, data)
  if player:hasSkill(self, true) then
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if table.contains(player.room.discard_pile, info.cardId) then
            return true
          end
        end
      end
      for _, info in ipairs(move.moveInfo) do
        if info.fromArea == Card.DiscardPile and not table.contains(player.room.discard_pile, info.cardId) then
          return true
        end
      end
    end
  end
end,
on_refresh = function(self, event, target, player, data)
  local room = player.room
  local ids = player:getTableMark("test4__muyu-turn")
  for _, move in ipairs(data) do
    if move.toArea == Card.DiscardPile then
      for _, info in ipairs(move.moveInfo) do
        if table.contains(room.discard_pile, info.cardId) then
          table.insertIfNeed(ids, info.cardId)
        end
      end
    end
    for _, info in ipairs(move.moveInfo) do
      if info.fromArea == Card.DiscardPile and not table.contains(room.discard_pile, info.cardId) then
        table.removeOne(ids, info.cardId)
      end
    end
  end
  room:setPlayerMark(player, "test4__muyu-turn", ids)
end,
}

local muyu_retrial = fk.CreateTriggerSkill{
  name = "#test4__muyu_retrial",
  mute = true,
  events ={fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.reason == "test4__muyu"
  end,
  on_cost = function (self, event, target, player, data)
    local cards = table.filter(player:getTableMark("test4__muyu-turn"),function (id)
      return Fk:getCardById(id).suit == Card.Spade
    end)
    local c = player.room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|.|.|.|"..table.concat(cards,","),
    "#test4__muyu-retrial::"..data.who.id, cards)
    if #c > 0 then
      self.cost_data = {c = c[1]}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke("test4__muyu",math.random(3,4))
    player.room:notifySkillInvoked(player, "test4__muyu")
    player.room:retrial(Fk:getCardById(self.cost_data.c), player, data, "test4__muyu")
  end,
}
Fk:loadTranslationTable{
  ["test4__muyu"] = "暮雨",
  [":test4__muyu"] = "当你使用【杀】时，你可以将此【杀】改为雷【杀】或冰【杀】；结束阶段，若本回合进入弃牌堆的黑桃牌总点数大于8，你可令一名角色进行【闪电】判定，且你可以将其中一张黑桃牌作为判定牌。",

  ["#test4__muyu_trigger"] = "暮雨",
  ["#test4__muyu_retrial"] = "暮雨",
  ["#test4__muyu"] = "暮雨：你可以将此【杀】改为雷【杀】或冰【杀】",
  ["#test4__muyu-ask"] = "暮雨：你可令一名角色进行【闪电】判定",
  ["#test4__muyu-retrial"] = "暮雨：你可以选择一张黑桃牌作为%dest的判定牌",

  ["$test4__muyu1"] = "此生如朝露，身名俱灭。",
  ["$test4__muyu2"] = "忘川无波澜，引渡徘徊。",
  ["$test4__muyu3"] = "我为逝者哀哭……",
  ["$test4__muyu4"] = "暮雨，终将落下。",
}


local juju = fk.CreateViewAsSkill{
  name = "test4__juju",
  anim_type = "defensive",
  pattern = "slash",
  prompt = "#test4__juju",
  interaction = function (self, player)
    local all = {"$Hand","$Equip","$Judge"}
    local ask = {}
    for i, s in ipairs({"h","e","j"}) do
      if #player:getCardIds(s) == 1 then
        table.insert(ask,all[i])
      end
    end
    return UI.ComboBox{
      choices = ask,
      all_choices = all,
    }
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards,player)
    if self.interaction.data == nil then return end
    local all = {"h","e","j"}
    local ids
    for i, s in ipairs({"$Hand","$Equip","$Judge"}) do
      if self.interaction.data == s then
        ids = player:getCardIds(all[i])
        if #ids ~= 1 then return end
      end
    end
    local c = Fk:cloneCard("slash")
    c.skillName = self.name
    c:addSubcards(ids)
    return c
  end,
  enabled_at_play = function (self, player)
    for _, s in ipairs({"h","e","j"}) do
      if #player:getCardIds(s) == 1 then return true end
    end
    return false
  end,
  enabled_at_response = Util.FalseFunc,
}

local juju_skip = fk.CreateTriggerSkill{
  name = "#test4__juju_skip", 
  events = {fk.BuryVictim},-- 死亡奖惩
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill("test4__juju") and data.damage and data.damage.from == player and target.rest == 0 --休整
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player.room:addPlayerMark(player, MarkEnum.SlashResidue)
    data.extra_data = data.extra_data or {}
    data.extra_data.skip_reward_punish = true
  end,
}

Fk:loadTranslationTable{
  ["test4__juju"] = "踽踽",
  [":test4__juju"] = "你可以将一个区域内的最后一张牌当【杀】使用；你击杀角色后：1.不执行身份奖惩；2.【杀】的使用上限+1。",

  ["#test4__juju_skip"] = "踽踽",
  ["#test4__juju"] = "踽踽：你可以将一个区域内的最后一张牌当【杀】使用",

  ["$test4__juju1"] = "切勿回头，来处无路可走。",
  ["$test4__juju2"] = "又一场雨…一场空白…",
}

local huaiwu = fk.CreateTriggerSkill{
  name = "test4__huaiwu",
  frequency = Skill.Compulsory,
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if not player:hasSkill("test4__huaiwu") then return false end
        for _, move in ipairs(data) do
          for _, info in ipairs(move.moveInfo) do
            if (move.to == player.id and move.toArea == Card.PlayerEquip and player:getMark("test4__huaiwu") == 0)
            or (move.from == player.id and info.fromArea == Card.PlayerEquip) then
              return Fk:getCardById(info.cardId).sub_type == Card.SubtypeWeapon
            end
          end
        end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        local card = Fk:getCardById(info.cardId)---@cast card EquipCard
        if move.to == player.id and move.toArea == Card.PlayerEquip and 
        card.sub_type == Card.SubtypeWeapon and player:getMark("test4__huaiwu") == 0 then
          self:onAcquire(player)
        elseif move.from == player.id and info.fromArea == Card.PlayerEquip and 
        card.sub_type == Card.SubtypeWeapon and card.name == player:getMark("test4__huaiwu") then
          local skills = card:getEquipSkills(player)
          if #skills > 0 then
            room:handleAddLoseSkills(player, table.concat(table.map(skills, Util.NameMapper), "|"), self.name,false)
          end
        end
      end
    end
  end,
  on_acquire = function (self, player, is_start)
    local room = player.room
    local name = ""
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
      for i = 1, #e.data, 1 do
        local move = e.data[i]
        if move.toArea == Card.PlayerEquip and move.to == player.id then
          for j = 1, #move.moveInfo, 1 do
            local info = move.moveInfo[j]
            local card = Fk:getCardById(info.cardId)
            if card.type == Card.TypeEquip and card.sub_type == Card.SubtypeWeapon then
              name = card.name
              return true
            end
          end
        end
      end
    end, Player.HistoryGame)
    if name ~= "" then
      local card = Fk:cloneCard(name)---@cast card EquipCard
      local skills = card:getEquipSkills(player)
      if #skills > 0 then
        room:handleAddLoseSkills(player, table.concat(table.map(skills, Util.NameMapper), "|"), self.name,false)
      end
      --room:handleAddLoseSkills(player, card.equip_skill.name, nil, false, false)
      room:setPlayerMark(player, "test4__huaiwu", name)
      room:setPlayerMark(player, "@test4__huaiwu", Fk:translate(name))
      player:broadcastSkillInvoke(self.name)
      player.room:notifySkillInvoked(player, self.name)
    end
  end,
  on_lose = function (self, player, is_death)
    local room = player.room
    if player:getMark("test4__huaiwu") ~= 0 then
      --[[
      local card = Fk:cloneCard(player:getMark("test4__huaiwu"))---@cast card EquipCard
      if not table.find(player:getEquipments(card.sub_type), function (id)
        return Fk:getCardById(id).name == player:getMark("test4__huaiwu")
      end) then
        local skills = card:getEquipSkills(player)
        if #skills > 0 then
          room:handleAddLoseSkills(player, table.concat(table.map(skills, Util.NameMapper), "|"), self.name)
        end
        local skill = card.equip_skill
        room:handleAddLoseSkills(player, "-"..skill.name, nil, false, false)
      end--]]
      room:setPlayerMark(player, "test4__huaiwu", 0)
      room:setPlayerMark(player, "@test4__huaiwu", 0)
    end
  end,
}
local huaiwu_attackrange = fk.CreateAttackRangeSkill{
  name = "#test4__huaiwu_attackrange",
  correct_func = function (self, from, to)
    if from:getMark("test4__huaiwu") ~= 0 and from:hasSkill(huaiwu) then
      local card = Fk:cloneCard(from:getMark("test4__huaiwu"))
      if card.sub_type == Card.SubtypeWeapon then
        local n = card.attack_range
        local nums = {}
        if #from:getEquipments(Card.SubtypeWeapon) > 0 then
          for _, id in ipairs(from:getEquipments(Card.SubtypeWeapon)) do
            table.insert(nums, Fk:getCardById(id).attack_range)
          end
        end
        if #nums > 0 then
          local orig = math.max(table.unpack(nums))
          if n > orig then
            return n - orig
          else
            return 0
          end
        else
          return n
        end
      end
    end
    return 0
  end,
}

Fk:loadTranslationTable{
  ["test4__huaiwu"] = "怀无",
  [":test4__huaiwu"] = "锁定技，你视为装备着你首次使用的武器牌。",

  ["@test4__huaiwu"] = "怀无",

  ["$test4__huaiwu1"] = "流淌吧，过往的刀光。",
  ["$test4__huaiwu2"] = "我拔刀的理由，从前、如今、往后，只有一个。",
}

muyu:addRelatedSkill(muyu_retrial)
muyu:addRelatedSkill(muyu_trigger)
huangquan:addSkill(muyu)
juju:addRelatedSkill(juju_skip)
huangquan:addSkill(juju)
huaiwu:addRelatedSkill(huaiwu_attackrange)
huangquan:addSkill(huaiwu)



local shajin = General:new(extension, "test4__shajin", "test_hu", 4)

Fk:loadTranslationTable{
  ["test4__shajin"] = "砂金",--名字
  ["#test4__shajin"] = "囚石铸金",--称号
  ["designer:test4__shajin"] = "zuozhe",--作者
  ["cv:test4__shajin"] = "cv",--cv
  ["illustrator:test4__shajin"] = "huashi",--画师

  ['~test4__shajin'] = '满盘皆输阿……',
}

local zhangyan = fk.CreateTriggerSkill{
  name = "test4__zhangyan"
}

Fk:loadTranslationTable{
["test4__zhangyan"] = "掌宴",
[":test4__zhangyan"] = "当你发动“囚境”时，你可以弃置至多三张牌并从“是”多、“否”多中预测一项；若预测正确：“囚境”目标数+1，你摸弃牌数两倍的牌；不正确：重置“囚境”，下次发动“囚境”时你成为额外目标。",
["#test4__zhangyan"] = "掌宴：你可以弃置至多三张牌并预测“囚境”",

["$test4__zhangyan1"] = "买定离手，全押。",
["$test4__zhangyan2"] = "赌局还未结束，重码加注咯。",
}

local qiujing = fk.CreateActiveSkill{
  name = "test4__qiujing",
  prompt = function (self, selected_cards, selected_targets)
    return "#test4__qiujing-ask:::"..(Self:getMark("test4__qiujing") + 2)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name,Player.phase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.TrueFunc,
  feasible = function (self, selected, selected_cards, player)
    return #selected == player:getMark("test4__qiujing") + 2
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    ------掌宴
    if player:getMark("@@test4__qiujing") > 0 then
      table.insertIfNeed(effect.tos,player.id)
    end
    room:setPlayerMark(player,"@@test4__qiujing",0)
    local cai = nil
    local c
    if not player:isNude() and player:hasSkill("test4__zhangyan") then
      local cards,choice = U.askforChooseCardsAndChoice(player, player:getCardIds("he"), {"yes","no"}, "test4__zhangyan", "#test4__zhangyan",{"Cancel"},1,3)
      if choice ~= "Cancel" then
        room:useSkill(player,zhangyan,function () end)
        room:throwCard(cards,"test4__zhangyan",player,player)
        cai = choice
        c = #cards
      end
    end
    ------掌宴
    local ps = table.map(effect.tos,function (id)
      return room:getPlayerById(id)
    end)
    local ret = U.askForJointChoice(ps,{"yes","no"},"test4__qiujing","#test4__qiujing",true)
    local yes = table.filter(effect.tos,function (id)
      return ret[id] == "yes"
    end)
    local no = table.filter(effect.tos,function (id)
      return ret[id] == "no"
    end)
    if cai ~= nil then --掌宴
      if (#yes > #no and cai == "yes") or (#yes < #no and cai == "no") then
        player:drawCards(2*c,"test4__zhangyan")
        room:addPlayerMark(player,"test4__qiujing",1)        
      else
        room:setPlayerMark(player,"test4__qiujing",0)
        room:setPlayerMark(player,"@@test4__qiujing",1)
      end
    end
    if #no == #effect.tos or #yes == #effect.tos then
      for _, p in ipairs(room:getAlivePlayers()) do
        if table.contains(effect.tos,p.id) and not p.dead then
          if ret[p.id] == "yes" then
            room:damage{
              from = player,
              to = p,
              damage = 1,
              skillName = self.name,
            }
          elseif not p:isNude() then
            room:askForDiscard(p,1,1,true,self.name,false)
          end
        end
      end
    else
      for _, p in ipairs(room:getAlivePlayers()) do
        if table.contains(no,p.id) and not p.dead then
          room:damage{
            from = player,
            to = p,
            damage = #yes,
            skillName = self.name,
          }
        end
      end
    end
  end,
}


Fk:loadTranslationTable{
  ["test4__qiujing"] = "囚境",
  [":test4__qiujing"] = "出牌阶段限一次，你可令两名角色秘密选择是否“出卖对方”，之后明示结果，若结果：1.一致，选是/否者受到1点伤害/弃1张牌；2.不一致，选否者各受到X点伤害（X为选是者数）。",

  ["@@test4__qiujing"] = "囚境",
  ["#test4__qiujing"] = "囚境：是否“出卖对方”",
  ["#test4__qiujing-ask"] = "囚境：你可以令%arg名角色秘密选择是否“出卖对方”",

  ["$test4__qiujing1"] = "让我们尽情向彼此展现自己的价值吧。",
  ["$test4__qiujing2"] = "一枚不知价值的筹码，一张不知花色的底牌。",
}

shajin:addSkill(qiujing)
shajin:addSkill(zhangyan)


local jialahe = General:new(extension, "test4__jialahe", "test_feng", 3)

Fk:loadTranslationTable{
  ["test4__jialahe"] = "加拉赫",--名字
  ["#test4__jialahe"] = "狮子之尾",--称号
  ["designer:test4__jialahe"] = "zuozhe",--作者
  ["cv:test4__jialahe"] = "cv",--cv
  ["illustrator:test4__jialahe"] = "huashi",--画师

  ['~test4__jialahe'] = '如果能重来…',
}

local zhuoniang = fk.CreateActiveSkill{
  name = "test4__zhuoniang",
  prompt = "#test4__zhuoniang",
  anim_type = "defensive",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  min_target_num = 1,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0
  end,
  on_use = function (self, room, effect)
    local t = room:getPlayerById(effect.tos[1])
    room:addPlayerMark(t,"@@test4__zhuoniang",1)
    room:damage{
      from = room:getPlayerById(effect.from),
      to = t,
      damage = 1,
      damageType = fk.FireDamage,
      skillName = self.name,
    }
  end,
}

local zhuoniang__trigger = fk.CreateTriggerSkill{
  name = "#test4__zhuoniang__trigger",
  mute = true,
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill("test4__zhuoniang") and player == target and player.phase == Player.Start then
      local ps = {}
      for _, p in ipairs(player.room:getAllPlayers()) do
        if p:getMark("@@test4__zhuoniang") > 0 then
          if p.dead then
            player.room:setPlayerMark(p,"@@test4__zhuoniang",0)
          else
            table.insert(ps,p)
          end
        end
      end
      self.cost_data = {p = ps}
      return #ps > 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("test4__zhuoniang",math.random(1,2))
    room:notifySkillInvoked(player, "test4__zhuoniang",nil,table.map(self.cost_data.p,Util.IdMapper))
    for _, p in ipairs(self.cost_data.p) do
      room:recover{
        who = p,
        num = p:getMark("@@test4__zhuoniang") * 2,
        skillName = "test4__zhuoniang",
        recoverBy = player,
      }
      room:setPlayerMark(p,"@@test4__zhuoniang",0)
    end
  end,
}

Fk:loadTranslationTable{
  ["test4__zhuoniang"] = "灼酿",
  [":test4__zhuoniang"] = "出牌阶段限一次，你可以对一名角色造成1点火焰伤害，该角色于你的下个准备阶段回复2点体力。",

  ["@@test4__zhuoniang"] = "灼酿",
  ["#test4__zhuoniang__trigger"] = "灼酿",
  ["#test4__zhuoniang"] = "灼酿：你可以对一名角色造成1点火焰伤害，其于你的下个准备阶段回复2点体力",

  ["$test4__zhuoniang1"] = "从你开始吧。 ",
  ["$test4__zhuoniang2"] = "瞧着点。",
}


local hanming = fk.CreateActiveSkill{
  name = "test4__hanming",
  prompt = "#test4__hanming",
  anim_type = "defensive",
  target_num = 1,
  can_use = function(self, player)
    return player:getMark("#test4__hanming-turn") == 0
  end,
  card_filter = Util.FalseFunc,
  min_target_num = 1,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    local t = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0 and not table.contains(player:getTableMark("test4__hanming-turn"),to_select) and 
    not t:isProhibited(t, Fk:cloneCard("analeptic"))
  end,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    local t = room:getPlayerById(effect.tos[1])
    room:addTableMark(player,"test4__hanming-turn",t.id)
    room:useVirtualCard("analeptic",nil,t,t,self.name)
    if U.askForPlayCard(room,t,nil,nil,"test4__hanming") == nil then
      if not player:isNude() then
        room:askForDiscard(player,1,1,true,self.name,false)
      end
      room:setPlayerMark(player,"#test4__hanming-turn",1)
    end
  end,
}


Fk:loadTranslationTable{
  ["test4__hanming"] = "酣酩",
  [":test4__hanming"] = "出牌阶段，你可以指定一名本回合未以此指定过的角色，其视为使用一张【酒】并可以使用一张牌；若其未使用，你弃一张牌且本回合此技能失效。",

  ["#test4__hanming"] = "酣酩：你可以令一名角色视为使用一张【酒】，然后其可以使用一张牌",

  ["$test4__hanming1"] = "调剂一下。",
  ["$test4__hanming2"] = "生活就是如此美妙。",
}


zhuoniang:addRelatedSkill(zhuoniang__trigger)
jialahe:addSkill(zhuoniang)
jialahe:addSkill(hanming)


local zhigengniao = General:new(extension, "test4__zhigengniao", "test_xie", 3,3,General.Female)

Fk:loadTranslationTable{
  ["test4__zhigengniao"] = "知更鸟",--名字
  ["#test4__zhigengniao"] = "翼声纯律",--称号
  ["designer:test4__zhigengniao"] = "zuozhe",--作者
  ["cv:test4__zhigengniao"] = "cv",--cv
  ["illustrator:test4__zhigengniao"] = "huashi",--画师

  ['~test4__zhigengniao'] = '演出…还没…',
}

local xieyue = fk.CreateActiveSkill{
  name = "test4__xieyue",
  prompt = "#test4__xieyue",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and 
    table.find(Fk:currentRoom().alive_players,function (p)
      return p.hp ~= player.hp
    end)
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    for _, t in ipairs(room:getOtherPlayers(player)) do
      if t.hp > player.hp then
        room:loseHp(t,1,self.name)
      elseif t.hp < player.hp then
        room:recover{
          who = t,
          num = 1,
          skillName = self.name,
          recoverBy = player,
        }
      end
    end
    local n = #table.filter(room:getOtherPlayers(player),function (p)
      return p.hp == player.hp
    end)
    if n == #room:getOtherPlayers(player) then
      player:setSkillUseHistory("test4__gongming",0,Player.HistoryGame)
    end
    if player:getHandcardNum() < n then
      player:drawCards(n - player:getHandcardNum(),self.name)
    elseif player:getHandcardNum() > n then
      room:askForDiscard(player,player:getHandcardNum() - n,player:getHandcardNum() - n,false,self.name,false)
    end
  end,
}


Fk:loadTranslationTable{
  ["test4__xieyue"] = "谐乐",
  [":test4__xieyue"] = "出牌阶段限一次，你可令所有体力值大于/小于你的角色失去/回复1点体力，然后你将手牌调整至X张（X为与你体力相同的其他角色数），若X等于其他角色数，重置“共鸣”。",

  ["#test4__xieyue"] = "谐乐：你可以令所有体力值大于/小于你的角色失去/回复1点体力",

  ["$test4__xieyue1"] = "希望世间纷争不再。",
  ["$test4__xieyue2"] = "今夜，灵魂彼此相拥。",
}


local gongming = fk.CreateActiveSkill{
  name = "test4__gongming",
  prompt = "#test4__gongming",
  frequency = Skill.Limited,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name,Player.HistoryGame) == 0
  end,
  interaction = function (self, player)
    return UI.ComboBox{
      choices = {"recover","loseHp"},
    }
  end,
  card_filter = Util.FalseFunc,
  min_target_num = 1,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and to_select ~= player.id
  end,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    local t = room:getPlayerById(effect.tos[1])
    for _, p in ipairs({player,t}) do
      if not p.dead then
        if self.interaction.data == "loseHp" then
          room:loseHp(p,1,self.name)
        else
          room:recover{
            who = p,
            num = 1,
            skillName = self.name,
            recoverBy = player,
          }
        end
      end
    end
  end,
}


Fk:loadTranslationTable{
  ["test4__gongming"] = "共鸣",
  [":test4__gongming"] = "限定技，出牌阶段，你可以与一名其他角色各回复或失去1点体力。",

  ["#test4__gongming"] = "共鸣：你可以与一名其他角色各回复或失去1点体力",

  ["$test4__gongming1"] = "愿歌声为我们带来胜利。",
  ["$test4__gongming2"] = "该进入新乐章了。",
}

zhigengniao:addSkill(xieyue)
zhigengniao:addSkill(gongming)


local botiou = General:new(extension, "test4__botiou", "test_lie", 4)

Fk:loadTranslationTable{
  ["test4__botiou"] = "波提欧",--名字
  ["#test4__botiou"] = "扬尘孤星",--称号
  ["designer:test4__botiou"] = "zuozhe",--作者
  ["cv:test4__botiou"] = "cv",--cv
  ["illustrator:test4__botiou"] = "huashi",--画师

  ['~test4__botiou'] = '呵呵，好枪法…',
}


local duizhi = fk.CreateActiveSkill{
  name = "test4__duizhi",
  prompt = "#test4__duizhi",
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    return to_select ~= player.id and not player:isProhibited(Fk:currentRoom():getPlayerById(to_select), Fk:cloneCard("slash"))
  end,
  feasible = function (self, selected, selected_cards)
    return #selected == 1
  end,
  on_use = function (self, room, effect)
    local slash = Fk:cloneCard("slash")
    slash.skillName = self.name
    room:useCard({
      from = effect.from,
      card = slash,
      tos = {{effect.tos[1]}},
      extraUse = true,
    })
  end,
}

local duizhi__trigger = fk.CreateTriggerSkill{
  name = "#test4__duizhi__trigger",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.PreCardEffect},
  can_trigger = function(self, event, target, player, data)
    return data.to == player.id and
      data.card.trueName == "slash" and data.card.skillName == "test4__duizhi"
      and not (data.unoffsetable or data.disresponsive or
      table.contains(data.unoffsetableList or {}, player.id) or
      table.contains(data.disresponsiveList or {}, player.id))
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local p = room:getPlayerById(data.from)
    if not p.dead then
      local use =  room:askForUseCard(player,"slash",nil,"#test4__duizhi-invoke::"..p.id,true,{exclusive_targets = {p.id},bypass_distances = true})
      if use ~= nil  then
        room:useCard(use)
        data.extra_data = data.extra_data or {}
        data.extra_data.test4__duizhi = {from = p.id,tos = {player.id}}
        data.isCancellOut = true
        --return true
      end
    end
    data.unoffsetableList = data.unoffsetableList or {}
    table.insert(data.unoffsetableList, player.id)
  end,
  refresh_events = {fk.CardEffectCancelledOut},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill("test4__duizhi") and data.extra_data and data.extra_data.test4__duizhi
  end,
  on_refresh = function(self, event, target, player, data)
    player.room.logic:getCurrentEvent():addCleaner(function() --添加至抵消牌后，而非抵消时,以和左轮摸牌时机错开
      player.room:useSkill(player,duizhi,function ()
        duizhi:onUse(player.room,data.extra_data.test4__duizhi)
      end)
    end)
  end,
}

Fk:loadTranslationTable{
  ["test4__duizhi"] = "对峙",
  [":test4__duizhi"] = "出牌阶段限一次，你可视为对一名角色使用一张无视距离且不计次数的【杀】，其抵消该【杀】的方式改为：对你使用一张【杀】（无视距离）；若其抵消，结算后对其再次发动“对峙”。",

  ["#test4__duizhi__trigger"] = "对峙",
  ["#test4__duizhi"] = "对峙：你可以视为对一名角色使用一张【杀】，其抵消该【杀】的方式改为对你使用一张【杀】",
  ["#test4__duizhi-invoke"] = "对峙：对%dest使用一张【杀】以抵消此【杀】",

  ["$test4__duizhi1"] = "放马过来宝贝~",
  ["$test4__duizhi2"] = "来，动手，成全我！",
}

local zuolun = fk.CreateTriggerSkill{
  name = "test4__zuolun",
  events ={fk.CardUsing},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and data.from == player.id and
    data.card.trueName == "slash" and player:usedSkillTimes(self.name) == 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if table.find(player:getCardIds("h"),function (id)
      return Fk:getCardById(id).trueName == "slash"
    end) == nil then
      return
    end
    local n = #room:askForDiscard(player,1,5,false,self.name,true,"slash","#test4__zuolun")
    self.cost_data = {n = n}
    return n > 0
  end,
  on_use = function(self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.test4__zuolun = self.cost_data.n + 1
    data.additionalDamage = (data.additionalDamage or 0) + self.cost_data.n
  end,
}

local zuolun_out = fk.CreateTriggerSkill{
  name = "#test4__zuolun_out",
  anim_type = "drawcard",
  events = {fk.CardEffectCancelledOut},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill("test4__zuolun") and data.extra_data and data.extra_data.test4__zuolun
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(data.extra_data.test4__zuolun,"test4__zuolun")
  end,
}


Fk:loadTranslationTable{
  ["test4__zuolun"] = "左轮",
  [":test4__zuolun"] = "每回合限一次，当你使用【杀】时，你可以弃置至多5张【杀】令伤害加X，若如此做，此【杀】被抵消后，你摸X+1张牌（X为弃置【杀】数）。",

  ["#test4__zuolun_out"] = "左轮",
  ["#test4__zuolun"] = "左轮：你可以弃置至多5张【杀】",

  ["$test4__zuolun1"] = "上膛。",
  ["$test4__zuolun2"] = "再跑快点！",
}


duizhi:addRelatedSkill(duizhi__trigger)
botiou:addSkill(duizhi)
zuolun:addRelatedSkill(zuolun_out)
botiou:addSkill(zuolun)

local liuying = General:new(extension, "test4__liuying", "test_hui", 5, 5, General.Female)

Fk:loadTranslationTable{
  ["test4__liuying"] = "流萤",--名字
  ["#test4__liuying"] = "盈茧炽盛",--称号
  ["designer:test4__liuying"] = "zuozhe",--作者
  ["cv:test4__liuying"] = "cv",--cv
  ["illustrator:test4__liuying"] = "huashi",--画师

  ['~test4__liuying'] = '任务…终止…',
}

local liushang = fk.CreateTriggerSkill{
  name = "test4__liushang",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local choices = room:askForChoices(player,{"test4__hongyan","test4__jiaotu","test4__jianyuan"},1,3,self.name,"#test4__liushang")
    self.cost_data = {choices = choices}
    return true
  end,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, self.name)
    local c = self.cost_data.choices
    if #c == 0 then
      player:broadcastSkillInvoke(self.name,3)
    else
      player:broadcastSkillInvoke(self.name,math.random(1,2))
      player.room:changeMaxHp(player,-#c)
      for _, s in ipairs(c) do
        player.room:handleAddLoseSkills(player,s)
      end
    end
  end,
}


Fk:loadTranslationTable{
  ["test4__liushang"] = "流熵",
  [":test4__liushang"] = "锁定技，游戏开始时，你减少任意点体力上限并从“轰炎”、“焦土”、“茧源”中获得等量不同技能。",

  ["#test4__liushang"] = "流熵：你减少任意点体力上限并获得等量不同技能",

  ["$test4__liushang1"] = "火萤IV型，已就位。",
  ["$test4__liushang2"] = "没有退路，只能向前。",
  ["$test4__liushang3"] = "也许最后，我也能拥有自己的梦。",
}


--- 询问玩家使用一张虚拟卡，或从几种牌名中选择一种视为使用
---@param room Room @ 房间
---@param player ServerPlayer @ 要询问的玩家
---@param name string|string[] @ 使用虚拟卡名
---@param subcards? integer[] @ 虚拟牌的子牌，默认空
---@param skillName? string @ 技能名
---@param prompt? string @ 询问提示信息。默认为：请视为使用xx
---@param cancelable? boolean @ 是否可以取消，默认可以。
---@param bypass_times? boolean @ 是否无次数限制。默认无次数限制
---@param bypass_distances? boolean @ 是否无距离限制。默认有距离限制
---@param extraUse? boolean @ 是否不计入次数。默认不计入次数
---@param extra_data? UseExtraData|table @ 额外信息，因技能而异了
---@param skipUse? boolean @ 是否跳过使用。默认不跳过
---@return CardUseStruct? @ 返回卡牌使用框架。若取消使用则返回空
local askForUseVirtualCard = function(room, player, name, subcards, skillName, prompt, cancelable, bypass_times, bypass_distances, extraUse, extra_data, skipUse)
  --if player.dead then return end
  subcards = subcards or {}
  extraUse = (extraUse == nil) and true or extraUse
  skillName = skillName or "virtual_viewas"
  local all_names = type(name) == "table" and name or {name}
  if (cancelable == nil) then cancelable = true end
  if (bypass_times == nil) then bypass_times = true end
  extra_data = extra_data or {}
  extra_data.selected_subcards = subcards
  extra_data.skillName = skillName
  extra_data.virtualuse_allnames = all_names
  extra_data.bypass_times = bypass_times
  extra_data.bypass_distances = bypass_distances
  local names = table.filter(all_names, function (n)
    local card = Fk:cloneCard(n)
    card:addSubcards(subcards)
    card.skillName = skillName
    return card.skill:canUse(player, card, extra_data) and not player:prohibitUse(card)
    and table.find(room.alive_players, function (p)
      return not player:isProhibited(p, card) and card.skill:modTargetFilter(p.id, {}, player, card, not bypass_distances)
    end) ~= nil
  end)
  extra_data.virtualuse_names = names
  local dat
  if #names > 0 then
    if not prompt then
      if #all_names == 1 then
        prompt = ("#askForUseVirtualCard:::"..skillName..":"..all_names[1])
      else
        prompt = ("#askForUseVirtualCards:::"..skillName..":"..#names)
      end
    end
    _, dat = room:askForUseViewAsSkill(player, "virtual_viewas", prompt, cancelable, extra_data)
  end
  if #names == 0 then return end
  local card, tos
  if dat then
    tos = dat.targets
    card = Fk:cloneCard(#all_names == 1 and all_names[1] or dat.interaction)
    card:addSubcards(subcards)
    card.skillName = skillName
  else
    if cancelable then return end
    for _, n in ipairs(names) do
      card = Fk:cloneCard(n)
      card:addSubcards(subcards)
      card.skillName = skillName
      local temp = U.getDefaultTargets(player, card, bypass_times, bypass_distances)
      if temp then
        tos = temp
        break
      end
    end
  end
  if not tos then return end
  local use = {
    from = player.id,
    tos = table.map(tos, function(p) return {p} end),
    card = card,
    extraUse = extraUse,
  }
  if not skipUse then
    room:useCard(use)
  end
  return use
end

local ransheng = fk.CreateTriggerSkill{
  name = "test4__ransheng",
  frequency = Skill.Compulsory,
  anim_type = "support",
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.dying
  end,
  on_use = function(self, event, target, player, data)
  local room = player.room
  room:changeMaxHp(player,-1)
  if player.dead then return end
   room:recover{
     who = player,
     num =  1 - player.hp,
     recoverBy = player,
     skillName = self.name
   }
   player:drawCards(1,self.name)
   local x,y = {},{}
   for _, s in ipairs({"test4__hongyan","test4__jiaotu","test4__jianyuan"}) do
    if player:hasSkill(s,true) then
      table.insert(x,s)
    else
      table.insert(y,s)
    end
   end
   if #x == 0 or #y == 0 then return end
   local ask = {}
   local num = {}
   for _, n in ipairs(x) do
    for _, m in ipairs(y) do
      local t = "#test4__ransheng:::"..n..":"..m
      table.insert(ask,t)
      table.insert(num,{lose = n, acquire = m})
    end
   end
   table.insert(ask,"Cancel")
   local choices = player.room:askForChoice(player,ask,self.name)
   if choices ~= "Cancel" then
    for i, v in ipairs(ask) do
      if choices == v then
        room:handleAddLoseSkills(player, "-"..num[i].lose)
        room:handleAddLoseSkills(player, num[i].acquire)
      end
    end
   end
  end,
}

local ransheng_death = fk.CreateTriggerSkill{
  name = "#test4__ransheng_death",
  frequency = Skill.Compulsory,
  anim_type = "offensive",
  events = {fk.Death},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill("test4__ransheng", false, true)
  end,
  on_cost = function (self, event, target, player, data)
    return U.getDefaultTargets(player,Fk:cloneCard("slash"),true) ~= nil
  end,
  on_use = function (self, event, target, player, data)
    askForUseVirtualCard(player.room,player,"slash",nil,"test4__ransheng",nil,false)
  end,
}

Fk:loadTranslationTable{
["test4__ransheng"] = "燃生",
[":test4__ransheng"] = "锁定技，当你：1.濒死时，你减少1点体力上限，摸1张牌并将体力值回复至1点，然后你可将“流熵”中的一个已持有技能与一个未持有的技能互换；2.死亡时，你视为使用一张【杀】。",

["#test4__ransheng_death"] = "燃生",
["#test4__ransheng"] = "失去%arg，获得%arg2",

["$test4__ransheng1"] = "飞萤扑火，向死而生！",
["$test4__ransheng2"] = "为战而生，为生而战！",
["$test4__ransheng3"] = "直至一切，燃烧殆尽！",
}

local hongyan = fk.CreateTriggerSkill{
  name = "test4__hongyan",
  mute = true,
  events ={fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and target == player and data.card.name == "fire__slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name,math.random(1,2))
    player.room:notifySkillInvoked(player, self.name)
    room:damage{
      from = player,
      to = player,
      damage = 1,
      damageType = fk.FireDamage,
      skillName = self.name,
    }
    data.additionalDamage = (data.additionalDamage or 0) + 1
    if table.find(room:getOtherPlayers(player),function (p)
      return p.maxHp <= player.maxHp
    end) == nil then
      data.disresponsiveList = table.map(room:getAllPlayers(),Util.IdMapper)
      player:broadcastSkillInvoke(self.name,3)
    end
  end,
}

Fk:loadTranslationTable{
  ["test4__hongyan"] = "轰炎",
  [":test4__hongyan"] = "当你使用火【杀】时，你可对自身造成1点火焰伤害并令之伤害+1；若你的体力上限为全场唯一最少，该【杀】不可被响应。",

  ["$test4__hongyan1"] = "进攻，执行。",
  ["$test4__hongyan2"] = "预备，起爆。",
  ["$test4__hongyan3"] = "我将，点燃星海！",
}

local jiaotu = fk.CreateActiveSkill{
  name = "test4__jiaotu",
  prompt = function (self, selected_cards, selected_targets)
    return "#test4__jiaotu:::"..Self.maxHp
  end,
  anim_type = "control",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name,Player.HistoryPhase) == 0
  end,
  card_filter = function (self, to_select, selected, player)
    return #selected == 0
  end,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected < player.maxHp and not Fk:currentRoom():getPlayerById(to_select).chained
  end,
  feasible = function (self, selected, selected_cards, player)
    return #selected_cards == 1 and #selected == player.maxHp
  end,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards,self.name,player,player)
    for _, t in ipairs(room:getAllPlayers()) do
      if table.contains(effect.tos,t.id) then
        t:setChainState(true)
      end
    end
    if table.find(room:getOtherPlayers(player),function (p)
      return p.maxHp < player.maxHp
    end) == nil and player:isWounded() then
      room:recover{
        who = player,
        num =  1,
        recoverBy = player,
        skillName = self.name
      }
    end
  end,
}

local jiaotu_trigger = fk.CreateTriggerSkill{
  name = "#test4__jiaotu_trigger",
  frequency = Skill.Compulsory,
  anim_type = "offensive",
  events = { fk.AfterCardUseDeclared },
  can_trigger = function(self, _, target, player, data)
    return player:hasSkill(self) and player:usedSkillTimes("test4__jiaotu",Player.HistoryRound) > 0 and
    data.from and player.room:getPlayerById(data.from).chained and data.card.trueName == "slash" and data.card.name ~= "fire__slash"
  end,
  on_use = function (self, event, target, player, data)
    local card = Fk:cloneCard("fire__slash", data.card.suit, data.card.number)
    for k, v in pairs(data.card) do
      if card[k] == nil then
        card[k] = v
      end
    end
    if data.card:isVirtual() then
      card.subcards = data.card.subcards
    else
      card.id = data.card.id
    end
    card.skillNames = data.card.skillNames
    card.skillName = "test4__jiaotu"
    data.card = card
  end,
}


Fk:loadTranslationTable{
  ["test4__jiaotu"] = "焦土",
  [":test4__jiaotu"] = "出牌阶段限一次，你可弃1张牌并横置体力上限名角色，然后本轮所有横置角色使用的【杀】均转化为火【杀】；若你的体力上限为全场最少，你回复一点体力。",

  ["#test4__jiaotu_trigger"] = "焦土",
  ["#test4__jiaotu"] = "焦土：你可以弃置一张牌并横置%arg名角色",

  ["$test4__jiaotu1"] = "开始清扫。",
  ["$test4__jiaotu2"] = "行动四，点火。",
}

local jianyuan = fk.CreateTriggerSkill{
  name = "test4__jianyuan",
  events ={fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player.dead and player:usedSkillTimes(self.name) == 0
    and not player:isNude() and data.from and data.from ~= player and not data.from.dead and data.to == player
  end,
  on_cost = function (self, event, target, player, data)
    return #player.room:askForDiscard(player,1,1,true,self.name,true,nil,"#test4__jianyuan::"..data.from.id) > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #room:askForDiscard(data.from,1,1,true,self.name,true,nil,"#test4__jianyuan-dis::"..player.id) > 0 then
      if not data.from.chained then
        data.from:setChainState(true)
      end
    else
      room:recover{
        who = player,
        num =  1,
        recoverBy = player,
        skillName = self.name
      }
    end
    if table.find(room:getOtherPlayers(player),function (p)
      return p.hp >= player.hp
    end) then
      player:drawCards(2,self.name)
    end
  end,
}

Fk:loadTranslationTable{
  ["test4__jianyuan"] = "茧源",
  [":test4__jianyuan"] = "每回合限一次，其他角色对你造成伤害后，你可弃置1张牌并令其选择一项：1.你回复一点体力；2.其弃一张牌并横置；若你的体力值不为全场最少，你摸两张牌。",

  ["#test4__jianyuan"] = "茧源：你可以弃置一张牌令%dest进行“茧源”选择",
  ["#test4__jianyuan-dis"] = "茧源：你须弃置一张牌，否则%dest回复1点体力",

  ["$test4__jianyuan1"] = "我会继续战斗。",
  ["$test4__jianyuan2"] = "我为自我而战。",
}

ransheng:addRelatedSkill(ransheng_death)
jiaotu:addRelatedSkill(jiaotu_trigger)
liuying:addSkill(liushang)
liuying:addSkill(ransheng)
liuying:addRelatedSkill(hongyan)
liuying:addRelatedSkill(jiaotu)
liuying:addRelatedSkill(jianyuan)

local xianzhousanyueqi = General:new(extension, "test4__xianzhousanyueqi", "test_lie", 4,4,General.Female)

Fk:loadTranslationTable{
  ["test4__xianzhousanyueqi"] = "仙舟三月七",--名字
  ["#test4__xianzhousanyueqi"] = "盖世女侠",--称号
  ["designer:test4__xianzhousanyueqi"] = "zuozhe",--作者
  ["cv:test4__xianzhousanyueqi"] = "cv",--cv
  ["illustrator:test4__xianzhousanyueqi"] = "huashi",--画师

  ['~test4__xianzhousanyueqi'] = '江湖…难啊…',
}

local lixue = fk.CreateTriggerSkill{
  name = "test4__lixue",
  mute = true,
  anim_type = "control",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and not player:isNude()
    and player:usedSkillTimes(self.name) == 0
    and table.contains({Player.Start,Player.Judge, Player.Draw, Player.Play, Player.Discard, Player.Finish}, data.to)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local p,c = room:askForChooseCardAndPlayers(player,table.map(room:getOtherPlayers(player),Util.IdMapper),1,1,".","#test4__lixue:::"..Util.PhaseStrMapper(data.to))
    self.cost_data = {p = p[1],c = c}
    return #p > 0 and c
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local p = room:getPlayerById(self.cost_data.p)
    room:obtainCard(p,self.cost_data.c,true,fk.ReasonGive,player.id,self.name)
    room:setPlayerMark(p,"@@test4__lixue-phase",1)
    player:broadcastSkillInvoke(self.name,math.random(1,2))
    player.room:notifySkillInvoked(player, self.name)
    p:gainAnExtraPhase(data.to,false)
    local n = #player:getTableMark("test4__lixue-turn")
    room:setPlayerMark(player,"test4__lixue-turn",0)
    if n < 2 then
      return true
      --data.skipped = true      
    else
      player:broadcastSkillInvoke(self.name,math.random(3,4))
      player.room:notifySkillInvoked(player, self.name)
    end
  end,
}

local lixue_draw = fk.CreateTriggerSkill{
  name = "#test4__lixue_draw",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill("test4__lixue") then
      for _, move in ipairs(data) do
        if move.to and player.room:getPlayerById(move.to):getMark("@@test4__lixue-phase") > 0 and move.toArea == Player.Hand then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1,"test4__lixue")
    player.room:addTableMarkIfNeed(player,"test4__lixue-turn",1)
  end,
}

local lixue_use = fk.CreateTriggerSkill{
  name = "#test4__lixue_use",
  events ={fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill("test4__lixue") and target:getMark("@@test4__lixue-phase") > 0
    and data.card.trueName == "slash"
  end,
  on_cost = function (self, event, target, player, data)
    local u = U.askForPlayCard(player.room,player,nil,nil,"test4__lixue",nil,nil,true)
    self.cost_data = {u = u}
    return u
  end,
  on_use = function (self, event, target, player, data)
    player.room:useCard(self.cost_data.u)
    player.room:addTableMarkIfNeed(player,"test4__lixue-turn",2)
  end,
}


Fk:loadTranslationTable{
  ["test4__lixue"] = "立雪",
  [":test4__lixue"] = "每回合限一次，你的阶段开始前，你可以交给一名其他角色一张牌，其代你执行此阶段；本阶段其获得牌/使用【杀】后，你可以摸/使用一张牌。若你均执行，你额外执行此阶段。",

  ["#test4__lixue_draw"] = "立雪",
  ["#test4__lixue_use"] = "立雪",
  ["#test4__lixue"] = "立雪：你可以交给一名其他角色一张牌，令其代你执行%arg",

  ["@@test4__lixue-phase"] = "立雪",

  ["$test4__lixue1"] = "劳您担待了！",
  ["$test4__lixue2"] = "师傅，请喝茶！",
  ["$test4__lixue3"] = "哦！我全都懂了！",
  ["$test4__lixue4"] = "是时候展现真正的剑术了！",
}

lixue:addRelatedSkill(lixue_use)
lixue:addRelatedSkill(lixue_draw)
xianzhousanyueqi:addSkill(lixue)

local luanpo = General:new(extension, "test4__luanpo", "test_shi", 4, 4, General.Female)

Fk:loadTranslationTable{
  ["test4__luanpo"] = "乱破",--名字
  ["#test4__luanpo"] = "忍视眈眈",--称号
  ["designer:test4__luanpo"] = "zuozhe",--作者
  ["cv:test4__luanpo"] = "cv",--cv
  ["illustrator:test4__luanpo"] = "huashi",--画师

  ['~test4__luanpo'] = '就此…告辞…',
}

local huiluan = fk.CreateTriggerSkill{
  name = "test4__huiluan",
  events ={fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and data.from == player.id and
    (data.card.is_damage_card or data.card.type == Card.TypeBasic) and player:usedSkillTimes(self.name) == 0 and
    #TargetGroup:getRealTargets(data.tos) == 1
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local t = room:getPlayerById(TargetGroup:getRealTargets(data.tos)[1])
    local ps = table.filter(room:getOtherPlayers(player),function (p)
      return t:inMyAttackRange(p)
    end)
    if #ps == 0 then return end
    local p = room:askForChoosePlayers(player,table.map(ps,Util.IdMapper),1,999,"#test4__huiluan::"..t.id)
    self.cost_data = {p = p}
    return #p > 0
  end,
  on_use = function(self, event, target, player, data)
    local t = TargetGroup:getRealTargets(data.tos)
    local p = self.cost_data.p
    player.room:sortPlayersByAction(p)
    for _, q in ipairs(p) do
      TargetGroup:pushTargets(data.tos, q)
    end
    TargetGroup:removeTarget(data.tos, t[1])
    player.room:setPlayerMark(player,"test4__huiluan",t[1])
    data.card.skillName = "test4__huiluan"
  end,
}

local huiluan_use = fk.CreateTriggerSkill{
  name = "#test4__huiluan_use",
  events ={fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill("test4__huiluan") and player == target and data.card and data.card.skillName == "test4__huiluan"
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local t = room:getPlayerById(player:getMark("test4__huiluan"))
    self.cost_data = {t = t.id} -- 是id
    return not t.dead and (t.rest == 0) and not player:prohibitUse(data.card) and not player:isProhibited(t, data.card)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = { ---@type CardUseStruct
    from = player.id,
    tos = {{self.cost_data.t}},
    card = Fk:cloneCard(data.card.name),
    extraUse = true,
    disresponsiveList = table.map(room:getAllPlayers(),Util.IdMapper),
    }
    player:broadcastSkillInvoke("test4__huiluan")
    player.room:notifySkillInvoked(player,"test4__huiluan")
    room:useCard(use)
  end,
}

local huiluan_end = fk.CreateTriggerSkill{
  name = "#test4__huiluan_end",
  anim_type = "drawcard",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill("test4__huiluan") and data.card.skillName == "test4__huiluan"
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,"test4__huiluan",0)
    local t = TargetGroup:getRealTargets(data.tos)
    local n = #t
    room.logic:getCurrentEvent().parent:searchEvents(GameEvent.Damage, 999, function(d)
      local damage = d.data[1]
      if n > 0 and damage.card and damage.card.skillName == "test4__huiluan" and table.contains(t,damage.to.id) then
        table.removeOne(t,damage.to.id)
        n = n - 1
      end
    end)
    self.cost_data = {n = n}
    return n > 0
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(self.cost_data.n,"test4__huiluan")
  end,
}


Fk:loadTranslationTable{
  ["test4__huiluan"] = "绘乱",
  [":test4__huiluan"] = "每回合限一次，当你使用基本牌或伤害牌时，若目标数为1，你可以将此牌目标改为其攻击范围内任意名其他角色，你每因此造成伤害后视为对原目标使用一张不可被响应的同名牌。此牌结算后，你摸X张牌（X为目标中未受到此牌伤害的角色数）。",

  ["#test4__huiluan_use"] = "绘乱",
  ["#test4__huiluan_end"] = "绘乱",
  ["#test4__huiluan"] = "绘乱：你可以将此牌目标改为 %dest 攻击范围内任意名其他角色",

  ["$test4__huiluan1"] = "缭乱忍法，万彩绽！",
  ["$test4__huiluan2"] = "银河忍法，千变万化。",
}

huiluan:addRelatedSkill(huiluan_use)
huiluan:addRelatedSkill(huiluan_end)
luanpo:addSkill(huiluan)

return extension